package cn.lili.modules.member.mapper;


import cn.lili.modules.member.entity.dos.Extension;
import cn.lili.modules.member.entity.dos.Member;
import cn.lili.modules.member.entity.vo.ExtensionVO;
import cn.lili.modules.member.entity.vo.MemberVO;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * @author Bulbasaur
 * @since 2020-02-25 14:10:16
 */
public interface ExtensionMapper extends BaseMapper<Extension> {


    @Select("select a.*,c.username,c.nick_name,c.mobile,c.face from li_extension a left join li_member c on a.member_id = c.id  ${ew.customSqlSegment}")
    IPage<ExtensionVO> pageByMemberVO(IPage<Extension> page, @Param(Constants.WRAPPER) Wrapper<Extension> queryWrapper);


    @Select("select promotion_code from li_member  ${ew.customSqlSegment}")
    String queryBusinessOrder(@Param(Constants.WRAPPER) Wrapper<Member> queryWrapper);


    //根据会员id查看推广人信息
    @Select("select DISTINCT m.*,r.name as partnerName from li_extension e left join li_member m on e.extension = m.promotion_code " +
            "left join li_partner p on p.member_id = m.id  and p.partner_state = 0 and p.delete_flag = 0 and NOW() < DATE_FORMAT(p.end_time,'%Y-%m-%d') " +
            "left join li_role r on r.id = p.role_id ${ew.customSqlSegment}")
    MemberVO findByMemberId(@Param(Constants.WRAPPER) Wrapper<Extension> queryWrapper);
}